﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Medianamik.Core.DAL.SubSonicDAL;
using SubSonic;
using Publication=Medianamik.Core.Publication;

namespace Medianamik.Client.MVP.Model.DataAccess
{
    public abstract class MedianamikRepository<TConcreteTypeCollection, TConcreteType, TInterface> : 
        MedianamikRepositoryBase<TConcreteTypeCollection, TConcreteType, TInterface>, 
        IMedianamikRepository<TInterface>
        where TConcreteTypeCollection : ICollectionWithChildren<TConcreteTypeCollection, TConcreteType>, new()
        where TConcreteType : IRecordBase, new()
    {
        public IEnumerable<TInterface> ChildsOf(Guid nodeId, bool inclusive, int maxDepth)
        {
            return new TConcreteTypeCollection()
                .LoadChildNodes(nodeId, inclusive, maxDepth)
                .Cast<TInterface>();
        }

        public IEnumerable<TInterface> ParentsOf(Guid nodeId, bool inclusive, int maxDepth)
        {
            return new TConcreteTypeCollection()
                .LoadParentNodes(nodeId, inclusive, maxDepth)
                .Cast<TInterface>();
        }

        public IEnumerable<TInterface> All()
        {
            return new TConcreteTypeCollection().Load()
                .Cast<TInterface>();
        }

        public abstract TInterface Get(Guid id);
        public abstract TInterface Get(Guid nodeId, CultureInfo culture);
        public abstract TInterface Get(Guid id, ContentState contentState);
        public abstract TInterface Get(Guid nodeId, CultureInfo culture, ContentState contentState);
    }
}
